Search completed in 1.31 seconds.
GC Rooting Guide
re the underlying pointer. JS::Rooted must be constructed with a JSContext*, and optionally an initial value. There are typedefs available for the main types. ...
...s, it makes more sense to only root the GC thing once and reuse it through an indirect reference. Like a reference, a JS::Handle is immutable: it can only ever refer to the JS::Rooted<T> that it was created for. Similarly to JS::Rooted<T>, there are typedefs available for the main types: Template class Typedef JS::Handle<JS::Value> JS::HandleValue JS::Handle<
JSObject*> JS::HandleObject JS::Handle<JSString*> JS::HandleString JS::Handle<JSScript*> JS::HandleScript JS::Handle<jsid> JS::HandleId You should use JS::Handle<T> for all function parameters taking GC thing pointers (except out-parameters, which are described below). For example, instead of: JSObject * someFunction(JSContext *cx, JSObject* obj) { // ... ...
...operator - on a JS::Rooted<T> instance. JS::MutableHandle<T> is exactly like a JS::Handle<T> except that it adds a .set(T &t) method and must be created from a JS::Rooted<T> explicitly. There are typedefs for JS::MutableHandle<T>, the same as for the other templates: Template class Typedef JS::MutableHandle<JS::Value> JS::MutableHandleValue JS::MutableHandle<
JSObject*> JS::MutableHandleObject JS::MutableHandle<JSString*> JS::MutableHandleString JS::MutableHandle<JSScript*> JS::MutableHandleScript JS::MutableHandle<jsid> JS::MutableHandleId JS::MutableHandle<T> should be used for all out-parameters, for example instead of: bool maybeGetValue(JSContext *cx, JS::Value* valueOut) { // ... if (!wasError) ...
...And 4 more matches
WebIDL bindings
ouble double double double float float float float interface: non-nullable Foo& already_addRefed<Foo> Foo* OwningNonNull<Foo> interface: nullable Foo* already_addRefed<Foo> Foo* RefPtr<Foo> long int32_t int32_t int32_t long long int64_t int64_t int64_t object JS::Handle<
JSObject*> JS::MutableHandle<
JSObject*> JSObject* octet uint8_t uint8_t uint8_t sequence const Sequence<T>& nsTArray<T>& (outparam) short int16_t int16_t int16_t unrestricted double double double double unrestricted float float float float unsigned long uint32_t uint32_t uint32_t unsig...
... sequences, dictionaries, owning unions, and variadic arguments becomes nsCString. Nullable ByteString are represented by the same types as non-nullable ones, but the string will return true for IsVoid(). Returning null as a string value can be done using SetIsVoid() on the out param. object object is represented in three different ways, depending on use: object arguments become JS::Handle<
JSObject*>. They will be in the compartment of the passed-in JSContext. object return values become a JS::MutableHandle<
JSObject*> out param appended to the argument list. This comes after all IDL arguments, but before the ErrorResult&, if any, for the method. The return value is allowed to be in any compartment; bindings will wrap it into the context compartment as needed. object dictionary members and...
... using SequenceRooter and DictionaryRooter. Methods using object always get a JSContext* argument. ...
...And 4 more matches
JS_BindCallable
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. callable JS::Handle<JSObject*> Pointer to the function object to bind new this. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. callable JS::Handle<JSObject*> Pointer to the function object to bind new this. ...
JS_GetInstancePrivate
obj JS::Handle<JSObject*> The object for which to retrieve private data. ...
... obj JS::Handle<JSObject*> The object for which to retrieve private data. ...
JS_InstanceOf
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> Object to test. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> Object to test. ...
JS_LinkConstructorAndPrototype
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
JS_NewFunction
Requires request. In a JS_THREADSAFE build, the caller must ...
...Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. call JSNative Native C/C++ implementation of this function. nargs unsigned Number of arguments the...
JS::Handle
nerated, which is quicker and easier to fix than when relying on a separate rooting analysis. If you want to add additional methods to JS::Handle for a specific specialization, define a js::HandleBase<T> specialization containing them. ...
JS::MutableHandle
T> by using |JS::Rooted<T>::operator&()|. If you want to add additional methods to JS::MutableHandle for a specific specialization, define a js::MutableHandleBase<T> specialization containing them. ...
JS::PersistentRooted
nkey 38, PersistentRooted<T> itself cannot be a global variable, but from SpiderMonkey38, it can be declared as a global variable, and initialized later with init() method (bug 1107639). ...
JS::Rooted
ed<T> may be automatically coerced to a JS::Handle<T>. JS::Rooted<T> should be used whenever a local variable's value may be held live across a call which can trigger a GC. If you want to add additional methods to Rooted for a specific specialization, define a js::RootedBase<T> specialization containing them. ...
JS_BufferIsCompilableUnit
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::HandleObject The global object, or NULL. utf8 const char * String containing the script to compile. length size_t The length of utf8 in characters. ...
JS_DeepFreezeObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> An object to freeze. Description JS_DeepFreezeObject freezes obj, and all objects it refers to, recursively. ...
JS_DefaultValue
work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it. This article covers features introduced in SpiderMonkey 1.8.6 Converts a JavaScript object to a primitive value, using the semantics of that object's internal [[DefaultValue]] hook. Renamed to JS::ToPrimitive from JSAPI 44. Syntax bool JS_DefaultValue(JSContext *cx, JS::Handle<
JSObject*> obj, JSType hint, JS::MutableHandle<JS::Value> vp); Name Type Description cx JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> The object to convert. hint JSType The hint to pass to th...
JS_DefineFunction
Create a native function and assign it as a property to a specified JS object. Syntax JSFunction * JS_DefineFunction(JSContext *cx, JS::Handle<
JSObject*> obj, const char *name, JSNative call, unsigned nargs, unsigned attrs); JSFunction * JS_DefineUCFunction(JSContext *cx, JS::Handle<
JSObject*> obj, const char16_t *name, size_t namelen, JSNative call, unsigned nargs, unsigned attrs); JSFunction * JS_DefineFunctionById(JSContext *cx, JS::Handle<
JSObject*> obj, JS::Handle<jsid> id, JSNative call, unsigned nargs, unsigned attrs); // Added in SpiderMonkey 17 Name Type Description cx JSContext * The context in which to define the function. R...
JS_DefineFunctions
Name Type Description cx JSContext * The context in which to define functions. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> The object on which functions are to be defined. fs const JSFunctionSpec * A NULL-terminated array of function specifications. ...
JS_ExecuteScript
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::HandleObject The scope in which to execute the ...
JS_FreezeObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> An object to freeze. Description Freezes an object. This means that other code cannot delete, add or change any properties on the object. See ES5's Object.freeze method. ...
JS_GetArrayLength
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> The object to examine. lengthp uint32_t * Out parameter. On success, *lengthp receives the length of the array. ...
JS_GetClassObject
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. key JSProtoKey The key of the prototype. objp JS::MutableHandle<JSObject*> Out parameter. If successful, receive the class constructor. Description JS_GetClassObject gets the builtin class costructor for the specified prototype key. ...
JS_GetClassPrototype
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. key JSProtoKey The key of the prototype. objp JS::MutableHandle<JSObject*> Out parameter. If successful, receive the class prototype object. Description JS_GetClassPrototype gets the builtin class costructor for the specified prototype key. ...
JS_GetConstructor
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> The object whose constructor is to be returned. Description JS_GetConstructor retrieves the constructor property of a given object, obj. If the result is a Function object, JS_GetConstructor returns a pointer to that object. Otherwise, it reports an error and returns NULL. To get an object's prototype, use JS_GetPrototype. ...
JS_HasInstance
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> Constructor/prototype to test. v JS::Handle<JS::Value> The value to test. bp bool * Out parameter. On success, *bp receives the result of the test. ...
JS_InitStandardClasses
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> The global object to initialize. This object must be of a JSClass that has the JSCLASS_GLOBAL_FLAGS bits set. ...
JS_NewObject
Creates a new JavaScript object. Syntax // Added in SpiderMonkey 45 JSObject * JS_NewObject(JSContext *cx, const JSClass *clasp); bool JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle<
JSObject*> proto); // Obsolete since SpiderMonkey 38 JSObject * JS_NewObject(JSContext *cx, const JSClass *clasp, JS::Handle<
JSObject*> proto, JS::Handle<
JSObject*> parent); JSObject * JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle<
JSObject*> proto, JS::Handle<
JSObject*> parent); // Added in SpiderMonkey 1.8 Name Type Description cx JSContext * The context in which to create the new object. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. ...
JS_SetArrayLength
Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext. obj JS::Handle<JSObject*> The array to modify. length uint32_t Number of array elements to set. Description JS_SetArrayLength sets the .length property of an object obj. length indicates the number of elements. ...
Interfacing with the XPCOM cycle collector
nsISupports or non-nsISupports objects, as well as arrays of these pointers. Handling JSObjects fields If your class needs to store a pointer to a JSObject then you need to tell the cycle collector about it. The approach you should take is as follows. Firstly it must be held in a JS::Heap<JSObject *> field. For example, suppose your class nsFoo has field mSomeObj: private: ... JS::Heap<
JSObject*> mSomeObj; ... When you have something in the JS object pointer you need to use mozilla::HoldJSObjects to tell the GC to trace it and keep the object alive: ... mSomeObj = ... ; mozilla::HoldJSObjects(this); ... In the Unlink method (or destructor) you need to set the object pointer to NULL: NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFoo) ... NS_IMPL_CYCLE_COLLECTION_UNLINK(mSomeMember) ...